package main

import (
    "fmt"
    "time"
    "runtime"
)

func main(){
    //用go创建承载一个形参和返回值为空的函数
    go func(){
        defer fmt.Println("A.defer")

        func(){
            defer fmt.Println("B.defer")

            //退出协程
            runtime.Goexit()

            fmt.Println("B")
        }()

        fmt.Println("A")
    }()

    //有参和返回值
    //因为go是异步的，所以得不到返回值，需要使用管道channel
    go func(a int, b int) bool {
        fmt.Println("a = ",a,", b = ",b)
        return true
    }(10,20)

    for{
        time.Sleep(1 * time.Second)
    }
}